
use std::vec::Vec;
use std::str::FromStr;

use reqwest::{
    Url,
    Response,
    Result,
    StatusCode,
};
use regex::Regex;
use serde_json::{
    Value,
};

use super::account_info::AccountInfo;
use super::song_info::{ Artist, Album, SongInfo };

pub struct MusicApi {
}

impl MusicApi {

    pub fn login<'a>(&self, name: &str, password: &str) -> Result<AccountInfo<'a>> {
        let mut login_api: String;
        if self.is_phone_number(name) {
            login_api = format!("{}/login/cellphone?phone={}&password={}", super::BASE_URL, name, password);
        } else if self.is_email(name) {
            login_api = format!("{}/login?email={}&password={}", super::BASE_URL, name, password);
        } else {
            println!("Invalid Account!");
            return Ok(AccountInfo{
                name: "error",
                user_id: 0,
                avatar: "https:",
            });
        }

        println!("login_api: {}", login_api);
        let mut response = reqwest::get(&login_api)?;
        println!("response = {}", response.status());

        if response.status() == StatusCode::OK {
            println!("response body = {}", response.text()?);
        }

        Ok(AccountInfo {
            name: "xxx",
            user_id: 1024,
            avatar: "https://localhost:3000",
        })
    }

    pub fn search_son(&self, song_name: &str) -> Option<Vec<SongInfo>> {
        let url = format!("{}/search?keywords={}", super::BASE_URL, song_name);

        println!("url: {}", url);

        let response = reqwest::get(&url).unwrap().text().unwrap();
//        let response = r#"
//        {"result":{"songs":[{"id":400162138,"name":"海阔天空","artists":[{"id":11127,"name":"Beyond","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":34430029,"name":"华纳23周年纪念精选系列","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":999273600007,"size":14,"copyrightId":7002,"status":3,"picId":3273246124149810},"duration":323693,"copyrightId":7002,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":347230,"name":"海阔天空","artists":[{"id":11127,"name":"Beyond","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":34209,"name":"海阔天空","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":746812800000,"size":10,"copyrightId":1003,"status":1,"picId":102254581395219},"duration":326348,"copyrightId":7002,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":376199,"fee":8,"rUrl":null},{"id":387717,"name":"海阔天空","artists":[{"id":13283,"name":"信乐团","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":38408,"name":"海阔天空","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1075564800000,"size":10,"copyrightId":0,"status":1,"picId":109951163028211140},"duration":278000,"copyrightId":1416096,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":5343895,"fee":1,"rUrl":null},{"id":387668,"name":"海阔天空","artists":[{"id":13283,"name":"信乐团","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":38400,"name":"挑信","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1101830400000,"size":28,"copyrightId":14025,"status":3,"picId":119846767442613},"duration":279667,"copyrightId":14025,"status":0,"alias":["偶像剧《死了都要爱-信乐团的故事》片头曲"],"rtype":0,"ftype":0,"mvid":5343895,"fee":8,"rUrl":null},{"id":25780157,"name":"海阔天空","artists":[{"id":9263,"name":"Robynn & Kendy","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":2313008,"name":"Dear Diary","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1361116800007,"size":10,"copyrightId":7003,"status":3,"picId":2336462209041205},"duration":195788,"copyrightId":7003,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":255660,"name":"海阔天空 (Live)","artists":[{"id":8336,"name":"林忆莲","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":25533,"name":"Sandy Lam Concert MMXI 演唱会","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1338825600000,"size":25,"copyrightId":7003,"status":3,"picId":109951163062452320},"duration":259004,"copyrightId":7003,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":347319,"name":"海阔天空(live 93)","artists":[{"id":11127,"name":"Beyond","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":34218,"name":"Words & Music(华纳纸盒版)","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":741456000000,"size":8,"copyrightId":5003,"status":3,"picId":122045790696257,"alia":["Words & Music: Final Live With 家驹"]},"duration":375000,"copyrightId":7002,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":25702224,"name":"海阔天空 (Live)","artists":[{"id":3080,"name":"黄贯中","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":2282021,"name":"我是歌手第一季 第1期","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1358438400007,"size":7,"copyrightId":12009,"status":40,"picId":1710840092840653},"duration":303320,"copyrightId":404023,"status":0,"alias":["原唱：Beyond"],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":1313726466,"name":"Beyond -海阔天空 （DJ版）（浪子康 Remix）","artists":[{"id":12570153,"name":"浪子康","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":73609429,"name":"人走茶凉","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1538236800000,"size":2,"copyrightId":0,"status":0,"picId":109951163576148270},"duration":136635,"copyrightId":0,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":29017036,"name":"海阔天空","artists":[{"id":6211,"name":"幼稚园杀手","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":2965013,"name":"热门华语236","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1388505600004,"size":47,"copyrightId":0,"status":2,"picId":3297435373429925},"duration":224444,"copyrightId":0,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":27515047,"name":"海阔天空","artists":[{"id":9881,"name":"汪小敏","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":2623243,"name":"一声所爱 大地飞歌（第九期）","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1375200000007,"size":12,"copyrightId":0,"status":1,"picId":5630599045913351},"duration":178677,"copyrightId":0,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":347351,"name":"海阔天空","artists":[{"id":11127,"name":"Beyond","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":34222,"name":"乐与怒","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":736185600000,"size":11,"copyrightId":5003,"status":1,"picId":65970697667610},"duration":324825,"copyrightId":7002,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":376199,"fee":8,"rUrl":null},{"id":31877402,"name":"海阔天空 (Live)","artists":[{"id":7891,"name":"韩红","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":3142050,"name":"我是歌手第三季 第5期","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1422547200007,"size":7,"copyrightId":424010,"status":-1,"picId":2917004349702834},"duration":310000,"copyrightId":404023,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":308235,"name":"海阔天空(Live)","artists":[{"id":9952,"name":"谢安琪","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":30602,"name":"903 id    Club 谢安琪拉阔变奏厅 Live","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1222963200000,"size":21,"copyrightId":5003,"status":1,"picId":106652627911507},"duration":239000,"copyrightId":5003,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":347033,"name":"海阔天空(live 1996)","artists":[{"id":11127,"name":"Beyond","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":34181,"name":"Beyond的精彩 Live & Basic","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":830880000000,"size":25,"copyrightId":684010,"status":3,"picId":41781441867527},"duration":497528,"copyrightId":684010,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":5436067,"fee":8,"rUrl":null},{"id":28310909,"name":"海阔天空","artists":[{"id":13594,"name":"左右乐队","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":2771348,"name":"末时代","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1348675200000,"size":14,"copyrightId":1416189,"status":0,"picId":18675205000257810},"duration":394000,"copyrightId":1416189,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":347247,"name":"遥かなる梦に","artists":[{"id":11127,"name":"Beyond","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":34209,"name":"海阔天空","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":746812800000,"size":10,"copyrightId":1003,"status":1,"picId":102254581395219},"duration":322000,"copyrightId":1003,"status":0,"alias":["原曲:海阔天空"],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":28427790,"name":"海阔天空 (Live)","artists":[{"id":2110,"name":"曹格","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":2786870,"name":"我是歌手第二季 突围赛","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1395331200007,"size":7,"copyrightId":12009,"status":1,"picId":5864795022750093},"duration":273000,"copyrightId":404023,"status":0,"alias":["原唱：Beyond"],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":28798516,"name":"海阔天空","artists":[{"id":29809639,"name":"余家辉","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":2897098,"name":"中国新声代第二季 第七期","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1405267200007,"size":9,"copyrightId":0,"status":0,"picId":5771336534426985},"duration":245000,"copyrightId":0,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":115093,"name":"海阔天空","artists":[{"id":3706,"name":"林子祥","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":11277,"name":"港乐.林子祥","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1036080000000,"size":24,"copyrightId":7002,"status":1,"picId":871912720826751},"duration":330397,"copyrightId":7002,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":28875146,"name":"海阔天空 (Live)","artists":[{"id":11127,"name":"Beyond","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":2921018,"name":"The Story Live 2005","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1112284800007,"size":22,"copyrightId":0,"status":0,"picId":109951163972046200},"duration":369000,"copyrightId":7003,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":5347246,"fee":8,"rUrl":null},{"id":27937677,"name":"海阔天空","artists":[{"id":2116,"name":"陈奕迅","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":2698078,"name":"热门华语185","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1356969600004,"size":32,"copyrightId":0,"status":2,"picId":3421680187176214},"duration":328019,"copyrightId":0,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":33789167,"name":"海阔天空","artists":[{"id":1094178,"name":"汤晶锦","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":3263145,"name":"中国新声代 第三季 第五期","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1439136000007,"size":8,"copyrightId":0,"status":0,"picId":7993449535649037},"duration":217000,"copyrightId":0,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":327114,"name":"海阔天空","artists":[{"id":10559,"name":"张惠妹","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":32363,"name":"我要快乐?","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1140134400000,"size":10,"copyrightId":7002,"status":3,"picId":109951163271830290},"duration":282266,"copyrightId":7002,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":5643054,"fee":8,"rUrl":null},{"id":41602156,"name":" 海阔天空 吉他纯音乐","artists":[{"id":1075068,"name":"徐涛","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":3274009,"name":"梦","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1362240000000,"size":9,"copyrightId":0,"status":0,"picId":3376600209207369},"duration":321175,"copyrightId":0,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":346013,"name":"海阔天空(Live)","artists":[{"id":3080,"name":"黄贯中","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},{"id":6094,"name":"叶世荣","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},{"id":3116,"name":"黄家强","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":34106,"name":"别了家驹十五载 海阔天空音乐会","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p1.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1218556800000,"size":25,"copyrightId":5003,"status":1,"picId":2400233883461299},"duration":367072,"copyrightId":7003,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null},{"id":1360120940,"name":"Beyond-Beyond - 海阔天空 (MushrooM Bootleg)（MushrooM remix）","artists":[{"id":12459208,"name":"MushrooM","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":78629760,"name":"海阔天空","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1555758264273,"size":0,"copyrightId":0,"status":0,"picId":109951164012644660},"duration":191405,"copyrightId":0,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":418279424,"name":"海阔天空（箱琴版）","artists":[{"id":1132850,"name":"顾稚蔚","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":34742615,"name":"海阔天空（超吉音乐箱琴版）","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1466693540525,"size":1,"copyrightId":0,"status":1,"picId":17683445509803018},"duration":320821,"copyrightId":0,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":1300156575,"name":"海阔天空（Cover 刘心 / 王铮亮）","artists":[{"id":12193360,"name":"低才生","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":72174219,"name":"吉米阿加","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1533686400000,"size":13,"copyrightId":0,"status":0,"picId":109951163448615550},"duration":270811,"copyrightId":0,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":0,"rUrl":null},{"id":346089,"name":"海阔天空","artists":[{"id":11127,"name":"Beyond","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null}],"album":{"id":34110,"name":"25周年精选","artist":{"id":0,"name":"","picUrl":null,"alias":[],"albumSize":0,"picId":0,"img1v1Url":"https://p2.music.126.net/6y-UleORITEDbvrOLV0Q8A==/5639395138885805.jpg","img1v1":0,"trans":null},"publishTime":1205164800000,"size":48,"copyrightId":5003,"status":1,"picId":82463372084291,"alia":["Beyond 25th Anniversary"]},"duration":322560,"copyrightId":7002,"status":0,"alias":[],"rtype":0,"ftype":0,"mvid":0,"fee":8,"rUrl":null}],"songCount":348},"code":200}
//        "#;

        let mut value: Value = serde_json::from_str(&response).unwrap();

        let mut len = 0; {
            len = value["result"]["songs"].as_array().unwrap().len();
        }

        let mut songs = value["result"]["songs"].take();
        if len <= 0 {
            return None;
        }

        let mut song_list: Vec<SongInfo> = Vec::new();

        println!("len={}", len);

        for i in 0..len {
            let mut artist = songs[i]["artists"][0].take();
            let artist = Artist::new(
                artist["id"].as_u64().unwrap(),
                String::from_str(artist["name"].take().as_str().unwrap()).unwrap(),
                String::from_str(artist["img1v1Url"].as_str().unwrap()).unwrap()
            );

            let mut album = songs[i]["album"].take();
            let album = Album::new(
                album["id"].as_u64().unwrap(),
                String::from_str(album["name"].as_str().unwrap()).unwrap(),
                album["size"].as_u64().unwrap(),
            );

            let song = SongInfo::new(
                songs[i]["id"].as_u64().unwrap(),
                String::from_str(songs[0]["name"].as_str().unwrap()).unwrap(),
                songs[i]["duration"].as_u64().unwrap(),
                artist,
                album,
            );

            song_list.push(song);
        }

        Some(song_list)
    }

    pub fn get_song_url(&self, id: i32) -> Result<&str> {
        let url = format!("{}/song/url?id={}", super::BASE_URL, id);

        let response = reqwest::get(&url)?.text()?;

        println!("url = {}", response);

        Ok("xxx")
    }

    fn is_phone_number(&self, phone: &str) -> bool {
        let phone_re: Regex = Regex::new(r"^1[3|4|5|6|7|8|9]\d{9}").unwrap();
        return phone.len() == 11 && phone_re.is_match(phone);
    }

    fn is_email(&self, email: &str) -> bool {
        let email_re:Regex = Regex::new("[0-9|a-z|A-Z|_]*@[0-9|a-z|A-Z]*.[a-z]*").unwrap();
        return email.len() > 0 && email_re.is_match(email);
    }
}
